
<template>
  <div class="columnAuthManage">
    <CommonBtn label-name="字段权限设定管理" v-if="!button || (button.event!='add()' && button.event!='edit()' && button.event!='detail()') " :buttons="buttons" @onButtonClick="onButtonClick">
      <span slot="appendCondition" style="margin:0px 10px">表名:</span>
      <el-select slot="appendCondition" size="mini" v-model="tablesMemo" @change="selectChange">
        <el-option v-for="(item,index) of options" :label="item.tablesMemo" :value="item.tablesMemo" :key="'option_'+index"></el-option>
      </el-select>
      <span slot="conditions" v-for="(item,index) of conditions" :key="index" v-if="item.checked">{{item.label+":"+item.value}}</span>
    </CommonBtn>
    <CommonList ref="list" v-if="!button || (button.event!='add()' && button.event!='edit()' && button.event!='detail()')" :buttons="buttons"
                :columns="columns" :listUrl="listUrl" @tableSelect="tableSelect" :conditions="conditions"></CommonList>
    <CommonEdit v-if="button && (button.event=='add()' || button.event=='edit()' || button.event=='detail()')"
                :outBtn="button" :props="add"
                :original-data="row" :edit-url="$api.API_UPDATECOLUMNPERMISSIONINFO"
                @editBack="editBack"></CommonEdit>
    <search-pop-up :out-btn="button"
                   :props="columns" @close="close"
                   :out-conditions="conditions"
                   @conditionChange="conditionChange"></search-pop-up>
    <CommonExport :out-btn="button" :props="columns"
                  @close="close" :export-url="$api.API_COLUMNPERMISSIONEXPORT" :conditions="conditions"></CommonExport>
    <EnsurePopUp :out-btn="button" @close="close" @refresh="conditionChange" :original-data="row"
                 :disable-url="$api.API_BANCOLUNM"></EnsurePopUp>
  </div>
</template>

<script>
    import CommonList from "../../common/CommonList";
    import CommonBtn from "../../common/CommonBtn";
    import CommonEdit from "../../common/CommonEdit";
    import SearchPopUp from "../../common/SearchPopUp";
    import CommonExport from "../../common/CommonExport";
    import EnsurePopUp from "../../common/EnsurePopUp";
    export default {
        name:'columnAuthManage',
        data(){
            return{
                buttons:[
                    this.$config.BTNS.EDIT,
                    this.$config.BTNS.FORBIDEN,
                    this.$config.BTNS.DETAIL,
                    this.$config.BTNS.EXPORT,
                    this.$config.BTNS.SEARCH,
                ],
                columns:[
                    {
                        prop:'tablesMemo',
                        label:'数据表描述'
                    },
                    {
                        prop:'columnName',
                        label:'表字段',
                        search:true,
                        type:'text'
                    },
                    {
                        prop:'typeName',
                        label:'数据类型'
                    },
                    {
                        prop:'percision',
                        label:'字段长度'
                    },
                    {
                        prop:'nullValue',
                        label:'是否可为空'
                    },
                    {
                        prop:'defaultValue',
                        label:'默认值'
                    },
                    {
                        prop:'columnMemo',
                        label:'字段描述',
                        search:true,
                        type:'text'
                    },
                    {
                        prop:'addRoleName',
                        label:'新增角色权限'
                    },
                    {
                        prop:'changeRoleName',
                        label:'变更角色权限'
                    },
                    {
                        prop:'appRoleName',
                        label:'审核角色权限'
                    },
                    {
                        prop:'createUserName',
                        label:'创建者'
                    },
                    {
                        prop:'modifyUserName',
                        label:'最后修改者'
                    },
                    {
                        prop:'createTime',
                        label:'创建时间'
                    },
                    {
                        prop:'modifyTime',
                        label:'最后修改时间'
                    }
                ],
                listUrl:this.$api.API_GETCOLUMNPERMISSIONINFO,
                button:null,
                conditions:[],
                //编辑有下拉框选项
                row:{},
                add:{
                    label:'字段权限设定',
                    addItems:[
                        {name:'数据表名',prop:'tablesName',type:'text'},
                        {name:'表字段',prop:'columnName',type:'text'},
                        {name:'数据类型',prop:'typeName',type:'text'},
                        {name:'字段长度',prop:'percision',type:'text'},
                        {name:'是否可为空',prop:'nullValue',type:'text'},
                        {name:'默认值',prop:'defaultValue',type:'text'},
                        {name:'字段描述',prop:'columnMemo',type:'text'},
                        {name:'新增角色权限',prop:'fkAddRole',type:'select'},
                        {name:'变更角色权限',prop:'fkChangeRole',type:'select'},
                        {name:'审核角色权限',prop:'fkAppRole',type:'select'},
                        {name:'备注',prop:'memo',type:'textarea'},
                    ],
                },
                options:[],
                tablesMemo:''
            }
        },
        methods:{
            onButtonClick(item) {
                if (item.event == 'edit()'|| item.event == 'disable()' || item.event == 'detail()') {
                    if (!this.row || JSON.stringify(this.row) == '{}') {
                        this.$message.error("请选择一行数据")
                        return
                    }
                }
                if (item.event == 'add()') {
                    this.row = {}
                }

                this.button = item
            },
            editBack(item) {
                this.button = item
            },
            tableSelect(row) {
                this.row = row
                this.$delete (this.row,'createTime')
                this.$delete (this.row,'modifyTime')
            },
            conditionChange(conditions) {
                this.$refs.list.search()
            },
            close(item) {
                this.button = item
            },
            initData() {
                this.$http.get(this.$api.API_USER_GROUP_LIST).then(resp=>{
                    let options = [{label:'--请选择--',value:0}]
                    for (let i=0;i<resp.length;i++){
                        options.push({label:resp[i].userGroupName,value:resp[i].pkid})
                    }
                    this.add.addItems[7].options = options
                    this.add.addItems[8].options = options
                    this.add.addItems[9].options = options
                },msg=>{})
                this.$http.get(this.$api.API_TP_SELECTTABLE).then(resp=>{
                    this.options = resp
                },msg=>{})
            },
            selectChange() {
                if (this.tablesMemo.indexOf('请选择')>-1) {
                    this.listUrl = this.$api.API_GETCOLUMNPERMISSIONINFO
                } else {
                    this.listUrl = this.$api.API_GETCOLUMNPERMISSIONINFO+'?tablesMemo='+this.tablesMemo
                }
                this.$nextTick(()=>{
                    this.conditionChange()
                })
            }
        },
        created() {
            this.initData()
        },
        components:{CommonExport, SearchPopUp, CommonList,CommonBtn,CommonEdit,EnsurePopUp},
    }
</script>
